<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>自定义JS对象</title>
</head>
<body>

<table>
    <caption>商品表</caption>
    <tr>
        <th>名称</th>
        <th>价格</th>
        <th>库存</th>
    </tr>
</table>


















<script>
    let p1={
        name:'张三',
        age:18,
        say:function () {
            console.log('hello 我是'+this.name);

        }
    }
    console.log(p1);
    p1.say();

    //先定义一个空对象,再动态的添加属性和方法
    let p2={
    }

    p2.name='李四';
    p2.age=20;
    p2.eat = function (){
        console.log(this.name+'再吃东西')
    }
    console.log(p2)
    p2.eat();

    //3 定义一个数组 存放多个商品对象
    let productArr =[
        {title:'小米'},
        {title:'苹果'},
        {title:'华为'},
        {title:'魅族'}
    ];
    console.log(productArr);
    console.log(productArr[2]);








</script>
</body>
</html>